<?php
namespace app\admin\controller;


use app\common\logic\Users;
use app\common\model\Band;
use app\common\model\Bankroll;
use app\common\model\Check;
use app\common\model\FirstChat;
use app\common\model\LoginLog;
use app\common\model\MoneyDetail;
use app\common\model\MyPackage;
use app\common\model\Order;
use app\common\service\App;
use app\common\service\AppService;
use app\common\service\ChatService;
use think\Db;
use think\Exception;
use think\Loader;


class User extends Base
{

    function _initialize()
    {
        parent::_initialize();
        $this->assign('stamp',123);
    }

    public function index()
    {
        $where = [];
        if(!empty($_GET['nick_name'])){
            $where['a.nick_name|a.phone'] = ['like','%'.trim(input('get.nick_name')).'%'];
        }

        if(!empty(input('user_id'))){
            $where['a.user_id'] = trim(input('user_id'));
        }

        if(!empty($_GET['uuid'])){
            $where['a.user_id|a.uuid'] = ['like','%'.trim(input('get.uuid')).'%'];
        }



        if (is_numeric(input('status'))){
            $where['a.status'] = input('status');
        }

        if (is_numeric(input('sex'))){
            $where['a.sex'] = input('sex');
        }

        if(!empty($_GET['startDate'])&&empty($_GET['endDate'])){
            $where['a.create_time'] = ['>=',strtotime($_GET['startDate'])];
        }elseif(!empty($_GET['endDate'])&&empty($_GET['startDate'])){
            $where['a.create_time'] = ['<=',strtotime($_GET['endDate'])];
        }elseif(!empty($_GET['startDate'])&&!empty($_GET['endDate'])){
            $where['a.create_time'] = ['between',array(strtotime($_GET['startDate']),strtotime($_GET['endDate']))];
        }

        if (is_numeric(input('level'))){
            $where['e.level'] = input('level');
        }


        if (input('register_name')){
            $where['e.register_name'] = input('register_name');
        }

        if (!empty(input('place'))){
            $where['e.place'] = ['like','%'.trim(input('get.place')).'%'];
        }

        $model = new \app\common\model\Users();
        $money = $model->cache(15)->sum('money');
        $cash  = $model->cache(15)->sum('cash');
        $coin  = $model->cache(15)->sum('coin');
        $online_count = Db::name('user_extend')->where('online_status',1)->cache(15)->count();
        $rows = $model->userList($where);
        $this->assign([
            'title' => '用户管理',
            'rows' => $rows,
            'money' => $money,
            'cash' => $cash,
            'coin' => $coin,
            'online_count' => $online_count,
            'pageHTML' => $rows->render(),
        ]);
        return view();
    }


    /**
     * 用户分析
     */
    public function analysis()
    {
        $row = \app\common\model\Users::get(input('id'));
        //付费时间
        $map['user_id'] = input('id');
        $map['status']  = 1;
        $map['type']    = 1;
        $map['remark']  = ['like','%注册%'];

        $reg = Bankroll::where($map)->find();

        $map['remark'] = ['like','%充值%'];
        $or['user_id'] = input('id');
        $or['status']  = 1;
        $or['type']    = 1;
        $or['remark']  = ['like','%购买%'];
        $recharge = Bankroll::where(function ($query)use ($map){
            $query->where($map);
        })->whereOr(function ($query)use ($or){
            $query->where($or);
        })->order('b_id desc')->select();

        $recharge_sum = Bankroll::where(function ($query)use ($map){
            $query->where($map);
        })->whereOr(function ($query)use ($or){
            $query->where($or);
        })->sum('pay_money');
        $recharge_count = Bankroll::where(function ($query)use ($map){
            $query->where($map);
        })->whereOr(function ($query)use ($or){
            $query->where($or);
        })->count();

        //线上邀约记录
        $inv['user_id'] = input('id');
        $inv['status']  = ['between',[1,12]];
        $order = Order::where($inv)->with('user_to,user_to_extend')->order('order_id desc')->select();
        $order_sum   = Order::where($inv)->with('user_to,user_to_extend')->sum('price');
        $order_count = Order::where($inv)->with('user_to,user_to_extend')->count();

        //心币赠送记录
        $cha['user_id'] = input('id');
        $cha['is_give'] = 1;
        $chat = FirstChat::where($cha)->order('id desc')->select();

        $chat_count = FirstChat::where($cha)->count();
        $chat_sum = FirstChat::where($cha)->sum('price');

//        dd($row->extend->ip);
        $this->assign([
            'row' => $row,
            'reg' => $reg,
            'recharge' => $recharge,
            'order' => $order,
            'order_sum' => $order_sum,
            'order_count' => $order_count,
            'recharge_sum' => $recharge_sum,
            'recharge_count' => $recharge_count,
            'chat' => $chat,
            'chat_count' => $chat_count,
            'chat_sum' => $chat_sum
        ]);
        return view();
    }

    /**
     * 聊天记录
     */
    public function chat_record()
    {
        $search_user = null;
        $array = [];

        if (input('date')){

            if (input('uuid')){
                $where['user_id|uuid'] = input('uuid');
                $search_user = Users::where($where)->value('user_id');
            }

            $message = [
                'date'=> input('date'),//日期
            ];
            $history = ChatService::getIns()->getMessage()->History()->get($message);
            if ($history['code'] == 200){
                $url = $history['url'];

                $name = substr(strrchr($url,'/'),1);

                $pre  = "./public/download/";

                downFile($url,$pre);

                if (!file_exists($pre.$name)){
                    $this->error("聊天文件下载失败");
                }
                //解压文件
                $z = new \Unzip();
                $file = $z->unzip($pre.$name,$pre, true, false,true);
                $records = explode("\r\n",$file);

                $pass = [
                    'RC:TxtMsg',
                    'RC:ImgMsg'
                ];

                foreach ($records as $k => $v){
                    if (!empty($v)){

                        $str = mb_strstr($v,'{');
                        $arr = json_decode($str,true);
                        if ($search_user){
                            if ($search_user != dehashid($arr['fromUserId']) && $search_user != dehashid($arr['targetId']) ){
                                continue;
                            }
                        }

                        if (!in_array($arr['classname'],$pass)){
                            continue;
                        }

                        if (is_array($arr) && isset($arr['content'])){

                            switch ($arr['fromUserId']){
                                case "system":
                                    $arr['formInfo'] = [
                                        'user_id'    => 'system',
                                        'nick_name'  => "<span style=\"color: red\">系统管理员</span>",
                                        'header_img' => App::extend('sys_header_img'),
                                    ];
                                    break;
                                case 'sysCustomer':
                                    $arr['formInfo'] = [
                                        'user_id'    => 'sysCustomer',
                                        'nick_name'  => "<span style=\"color: red\">小助手</span>",
                                        'header_img' => App::extend('sys_header_img')
                                    ];
                                    break;
                                default:
                                    if (starts_with($arr['fromUserId'],"admin")){ //客服信息查询
                                        $user_id = dehashid(str_replace('admin','',$arr['fromUserId']));
                                        if (is_numeric($user_id)){
                                            $map['user_id'] = $user_id;
                                            $map['is_service'] = 1;
                                            $arr['formInfo'] = Db::name('admins')->where($map)->field('nick_name,header_img')->cache(3)->find();
                                            $arr['user_id']  = $arr['fromUserId'];
                                        }
                                    }else{
                                        $user_id = dehashid($arr['fromUserId']);
                                        $arr['formInfo'] = AppService::getUserInfo('user_id,nick_name,header_img',$user_id);
                                    }
                                    break;

                            }

                            switch ($arr['targetId']){
                                case "system":
                                    $arr['targetInfo'] = [
                                        'user_id'         => 'system',
                                        'nick_name'  => "<span style=\"color: red\">系统管理员</span>",
                                        'header_img' => App::extend('sys_header_img'),
                                    ];
                                    break;
                                case 'sysCustomer':
                                    $arr['targetInfo'] = [
                                        'user_id'         => 'sysCustomer',
                                        'nick_name'  => "<span style=\"color: red\">小助手</span>",
                                        'header_img' => App::extend('sys_header_img')
                                    ];
                                    break;
                                default:
                                    if (starts_with($arr['targetId'],"admin")){ //客服信息查询
                                        $user_id = dehashid(str_replace('admin','',$arr['targetId']));
                                        if (is_numeric($user_id)){
                                            $map['user_id'] = $user_id;
                                            $map['is_service'] = 1;
                                            $arr['targetInfo'] = Db::name('admins')->where($map)->field('nick_name,header_img')->cache(3)->find();
                                            $arr['user_id'] = $arr['targetId'];
                                        }
                                    }else{
                                        $user_id = dehashid($arr['targetId']);

                                        $arr['targetInfo'] = AppService::getUserInfo('user_id,nick_name,header_img',$user_id);

                                    }
                                    break;

                            }

                            $array[] = $arr;

                        }

                    }
                }

            }
        }


        $this->assign([
            'rows' => $array
        ]);

        return view();
    }
    


    public function user_batch()
    {
        $ids = input('id/a');
        $type = input('type');
        switch ($type){
            case 'is_real'://批量屏蔽
                foreach ($ids as $k => $id){
                    Db::startTrans();
                    try{

                        App::sendUsrMsg('system',hashid($id),'真人认证未通过审核,账号已屏蔽,请点击消息跳转审核!',['type'=>'real_check','data'=>null]);

                        Db::name('users')->where('user_id',$id)->update(['is_real'=>0]);
                        Db::commit();
                    }catch (Exception $e){
                        Db::rollback();
                        $this->error($e->getMessage());
                    }
                }

                $this->success('操作成功');
                break;
            default:
               break;
        }


        $this->error('操作失败');

    }


    /**
     * @return \think\response\View
     * 用户信息编辑
     */
    public function user_edit()
    {
        if(request()->isPost()){

            $data  = input('post.');
            $model = new Users();
            if (!empty($data['phone'])){
                $phone = Db::name('users')
                    ->where('phone',$data['phone'])
                    ->where('user_id','<>',$data['id'])
                    ->value('user_id');
                if ($phone){
                    $this->error('该手机号已注册');
                }
            }
            if (!empty($data['phone'])){
                $phone = Db::name('users')
                    ->where('uuid',$data['uuid'])
                    ->where('user_id','<>',$data['id'])
                    ->value('user_id');
                if ($phone){
                    $this->error('该账号已存在');
                }
            }

            $old = $model->where('user_id',$data['id'])->find();

            if ($old['is_real'] != $data['is_real']){
                //修改了真人认证
                if ($data['is_real'] == 0){
                    App::sendUsrMsg('system',hashid($data['id']),'真人认证未通过审核,账号已屏蔽,请点击消息跳转审核!',['type'=>'real_check','data'=>null]);
                }
            }

            $data['member_time'] = strtotime($data['member_time']);

            Db::name('user_extend')->strict(false)->where('user_id',$data['id'])->update($data);

            if ($data['id']){
                $map['user_id'] = $data['id'];
                $map['type']    = 6;
                MyPackage::where($map)->update(['num'=>$data['box6']]);
                $map['type']    = 5;
                MyPackage::where($map)->update(['num'=>$data['box5']]);
                $map['type']    = 4;
                MyPackage::where($map)->update(['num'=>$data['box4']]);
            }

            $result = $model->saveChange($data);
            if($result){
                $this->success('操作成功');
            }
            $this->error($model->getError());
        }
        $isTest = false;
        if (is_numeric(input('id'))){

            //测试服地址
            if (request()->domain() == config('alphaUrl')){
                $isTest = true;

            }

            $map['p.user_id'] = input('id');

            $map['p.type'] = ['in',[4,5,6]];

            $box  = array_key(MyPackage::getRows($map),'type');
            $this->assign([
                'box' => $box,
            ]);
        }

        $this->_show('users','user_id');

        $extend = Db::name('user_extend')->where('user_id',input('id'))->find();

        $this->assign([
            'title' => '用户信息编辑',
            'isTest' => $isTest,
            'extend' => $extend,
        ]);
        return view();
    }

    public function change()
    {
        $data = input();
        $result = Db::name('users')->update(['status'=>$data['type'],'user_id'=>$data['id']]);
        if($result !== false){
            \app\api\controller\Base::outRoomFunc($data['id'],\app\api\controller\Base::staticInfo('room_id',$data['id']));
            //改变用户状态后清空前端token
            cache('token_'.hashid($data['id']),null);
            if ($data['type'] == 0){

                //封禁用户发送封禁消息
                $this->banedUser($data['id'],$data['end_time']);
            }

            $this->success('操作成功');
        }
        $this->error('操作失败');
    }

    public function user_pass()
    {
        $id     = input('param.id');
        $result = Db::name('users')->where('user_id',$id)->delete();
        if ($result){
            \app\api\controller\Base::outRoomFunc($id,\app\api\controller\Base::staticInfo('room_id',$id));
            $this->success('删除成功');
        }
        $this->error('删除失败');
    }


    public function band()
    {
        $IMEI = input('IMEI');
        $user_id = input('user_id');
        $id = Db::name('band')->where('IMEI',$IMEI)->value('id');
        if ($id){
            $this->error('设备已被封禁');
        }
        $data['IMEI'] = $IMEI;
        $data['create_time'] = time();
        $data['update_time'] = time();
        $result = Band::insert($data);
        if ($result !== false){
            cache('token_'.hashid($user_id),null);
            \app\api\controller\Base::outRoomFunc($user_id,\app\api\controller\Base::staticInfo('room_id',$user_id));
            $this->banedUser($user_id);
            $this->success('封禁成功');
        }
        $this->error('封禁失败');
    }


    public function band_list()
    {
        $where = [];

        if(!empty($_GET['IMEI'])){
            $where['a.IMEI'] = input('get.IMEI');
        }

        $model = new Band();
        $rows = $model->getList($where);
        $this->assign([
            'title' => '封禁设备列表',
            'rows' => $rows,
            'pageHTML' => $rows->render(),
        ]);
        return view();
    }


    public function band_del()
    {
        $this->_del('band');
    }



    /**
     * 登陆日志列表
     */
    public function log()
    {
        $where = [];
        if(!empty($_GET['nick_name'])){
            $where['c.nick_name|c.phone'] = ['like','%'.trim(input('get.nick_name')).'%'];
        }

        if(!empty($_GET['uuid'])){
            $where['c.uuid|b.user_id'] = ['like','%'.trim(input('get.uuid')).'%'];
        }

        if (input('user_id')){
            $where['b.user_id'] = input('user_id');
        }

        if(!empty($_GET['ip'])){
            $where['b.ip'] = input('get.ip');
        }

        if(!empty($_GET['IMEI'])){
            $where['b.IMEI'] = input('get.IMEI');
        }

        $model = new LoginLog();
        $rows = $model->getList($where);
        $this->assign([
            'rows' => $rows,
            'pageHTML' => $rows->render(),
        ]);
        return view();
    }

    public function del()
    {
        $id     = input('param.id');
        $result = Db::name('login_log')->delete($id);
        if ($result){
            $this->success('删除成功');
        }
        $this->error('删除失败');
    }

    public function cate()
    {
        $this->_list2('users_category','create_time DESC');
        $this->assign([
            'title'=>'用户类型'
        ]);
        return view();
    }

    public function cate_edit()
    {
        if (request()->isPost()){
            $data   = input('post.');
            $result = Db::name('users_category')->strict(false)->where('cid',$data['id'])->update($data);
            if($result!==false){
                $this->success('保存成功','/user/cate');
            }
            $this->error('操作失败');
        }
        $this->_show('users_category','cid');
        return view();
    }



    /**
     * 用户资金明细列表
     */
    public function detail()
    {

        $id = $this->request->param('id');
        $where = [];
        if (is_numeric($id)){
            $where['a.user_id'] = $id;
        }

        if (input('keyword')){
            $where['u.nick_name|u.phone'] = ['like','%'.trim(input('keyword')).'%'];
        }

        if (input('uuid')){
            $where['u.uuid|a.user_id'] = ['like','%'.trim(input('uuid')).'%'];
        }

        if (is_numeric(input('type'))){
            $where['a.type'] = input('type');
        }


        if (is_numeric(input('sex'))){
            $where['u.sex'] = input('sex');
        }

        if (is_numeric(input('coin_type'))){
            $where['a.coin_type'] = input('coin_type');
        }

        if (input('remark')){
            $where['a.remark'] = ['like','%'.trim(input('remark')).'%'];
        }

        $where['a.status'] = 1;
        if(!empty($_GET['start'])&&empty($_GET['end'])){
            $where['a.create_time'] = ['>=',strtotime($_GET['start'])];
        }elseif(!empty($_GET['end'])&&empty($_GET['start'])){
            $where['a.create_time'] = ['<=',strtotime($_GET['end'])];
        }elseif(!empty($_GET['start'])&&!empty($_GET['end'])){
            $where['a.create_time'] = ['between',array(strtotime($_GET['start']),strtotime($_GET['end']))];
        }


        $model = new MoneyDetail();

        if (input('download') == 'download'){ //点击了下载
            /* 永不超时 */
            ini_set('max_execution_time', 0);
            $rows = $model->downloadList($where);
            //         $path = ROOT_PATH.'public'.DS.'download'.DS.'excel'; //找到当前脚本所在路径
            Loader::import('PHPExcel.PHPExcel');//手动引入PHPExcel.php
//         Loader::import('PHPExcel.PHPExcel.IOFactory.PHPExcel_IOFactory');//引入IOFactory.php 文件里面的PHPExcel_IOFactory这个类
            $PHPExcel = new \PHPExcel();//实例化
            $PHPSheet = $PHPExcel->getActiveSheet();
            $PHPSheet->setTitle("资金明细".date('Ymdhis')); //给当前活动sheet设置名称
            $PHPSheet->setCellValue("A1","id")//表格数据
            ->setCellValue("B1","用户昵称")
                ->setCellValue("C1","类型")
                ->setCellValue("D1","金额")
                ->setCellValue("E1","详情")
                ->setCellValue("F1","备注")
                ->setCellValue("G1","日期");
            if (empty($rows)) $this->error('暂无数据');
            $i = 1;
            foreach ($rows as $k => $v){
                $i++;
                $PHPSheet->setCellValue("A$i",$v['d_id'])
                    ->setCellValue("B$i",$v['nick_name'])
                    ->setCellValue("C$i",$v['type'] == 1 ? '收入': '支出')
                    ->setCellValue("D$i",$v['money'])
                    ->setCellValue("E$i",$v['title'])
                    ->setCellValue("F$i",$v['remark'])
                    ->setCellValue("G$i",$v['create_time']);
            }
            $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,"Excel2007");//创建生成的格式
            $date = date('Ymdhis');
            header('Content-Disposition: attachment;filename="资金明细'.$date.'.xlsx"');//下载下来的表格名
            header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
            $PHPWriter->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
            exit;

        }

        $rows = $model->money_detail_list($where);
        $this->assign([
            'title' => '资金明细',
            'rows' => $rows,
            'pageHTML' => $rows->render(),
        ]);
        return view('money_detail');
    }

    /**
     * Created by xiaosong
     * E-mail:306027376@qq.com
     * 发送极光推送
     */
    public function push()
    {
        if (request()->isPost()){
            $data = input('post.');
            $push_id = 'all';
            if (is_numeric($data['user_id'])){
                $push_id = Db::name('user_extend')->where('user_id',$data['user_id'])->value('j_push_id');
                if (empty($push_id)) $this->error('推送失败,用户无推送id');
            }
            $result = j_push($data['title'],$push_id);
            if ($result){
                $this->success('发布成功');
            }
        }
        $this->error('系统繁忙,请稍后重试');
    }

    /**
     * Created by xiaosong
     * E-mail:306027376@qq.com
     * 发送客服消息
     */
    public function customer()
    {
        if (request()->isPost()){
            $data = input('post.');
            $map['status'] = 1;
            if (is_numeric($data['user_id'])){
                $map['user_id'] = $data['user_id'];

            }
            $msg['url']   = $data['url'];
            $msg['img']   = $data['img'];
            $msg['title'] = $data['title'];
            Db::name('users')->where($map)->field('user_id')->chunk(1000,function ($users)use($msg){
                foreach($users as $user){
                    // 处理user模型对象
                    $userIds[] = hashid($user['user_id']);
                }

                \app\api\controller\Base::sendUsrMsg('sysCustomer',$userIds,$msg);

            });
            $this->success('发送成功',url('index'));
        }
        return view();
    }



    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 修改审核列表
     */
    public function check()
    {
        $model = new Check();
        $map   = [];
        if (input('nick_name')){
            $map['u.nick_name'] = ['like','%'.trim(input('nick_name')).'%'];
        }
        if (is_numeric('status')){
            $map['a.status'] = input('status');
        }
        $rows  = $model->getList($map);
        $this->assign([
            'title' => '修改审核列表',
            'pageHTML' => $rows->render(),
            'rows' => $rows,
        ]);
        return view();
    }

    /**
     * 审核批量操作
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     */
    public function batch()
    {
        $ids = input('id/a');
        $type = input('type');
        switch ($type){
            case 'delete':
                $result = Check::destroy($ids);
                break;
            default:
                if ($type == 'success'){
                    //通过
                    $result = Check::where('check_id','in',$ids)->update(['status'=>1]);
                }else{
                    //回滚
                    foreach ($ids as $k => $id){
                        Db::startTrans();
                        try{
                            $info = Db::name('check')->where('check_id',$id)->findOrFail();
                            if ($info['status'] != 2){
                                continue;
                            }
                            switch ($info['type']){
                                case 1:
                                    Db::name('users')->where('user_id',$info['user_id'])->update(['header_img'=>$info['before']]);
                                    $str = sprintf('您于%s修改的头像因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                                    //发送系统消息
                                    \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                                    break;
                                case 2:
                                    if (!is_numeric($info['extend'])){
                                        $this->error('参数错误');
                                    }
                                    if (empty($info['before'])){
                                        Db::name('user_img')->where('img_id',$info['extend'])->delete();
                                        $str = sprintf('您于%s添加的形象照因不符合规范系统已删除',date('Y-m-d H:i',$info['create_time']));
                                        //发送系统消息
                                        \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                                    }else{
                                        Db::name('user_img')->where('img_id',$info['extend'])->update(['img'=>$info['before']]);
                                        $str = sprintf('您于%s修改的形象照因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                                        //发送系统消息
                                        \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                                    }
                                    break;
                                case 3:
                                    Db::name('users')->where('user_id',$info['user_id'])->update(['sign'=>$info['before']]);
                                    $str = sprintf('您于%s修改的昵称因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                                    //发送系统消息
                                    \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                                    break;
                                case 4:
                                    Db::name('users')->where('user_id',$info['user_id'])->update(['nick_name'=>$info['before']]);
                                    $str = sprintf('您于%s修改的昵称因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                                    //发送系统消息
                                    \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                                    break;
                            }
                            Db::name('check')->where('check_id',$id)->update(['status'=>0]);
                        Db::commit();
                        }catch (Exception $e){
                            Db::rollback();
                            $this->error($e->getMessage());
                        }
                    }

                    $this->success('操作成功');
                }
                break;
        }
        if ($result !== false){
            $this->success('操作成功');
        }

        $this->error('操作失败');

    }

    public function edit()
    {
        $data = input();
        $info = Db::name('check')->where('check_id',$data['id'])->findOrFail();

        Db::startTrans();
        try{
            if ($data['status'] == 0){  //未通过审核  回滚数据
                switch ($info['type']){
                    case 1:
                        Db::name('users')->where('user_id',$info['user_id'])->update(['header_img'=>$info['before']]);
                        $str = sprintf('您于%s修改的头像因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                        //发送系统消息
                        \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                        break;
                    case 2:
                        if (!is_numeric($info['extend'])){
                            $this->error('参数错误');
                        }
                        if (empty($info['before'])){
                            Db::name('user_img')->where('img_id',$info['extend'])->delete();
                            $str = sprintf('您于%s添加的形象照因不符合规范系统已删除',date('Y-m-d H:i',$info['create_time']));
                            //发送系统消息
                            \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                        }else{
                            Db::name('user_img')->where('img_id',$info['extend'])->update(['img'=>$info['before']]);
                            $str = sprintf('您于%s修改的形象照因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                            //发送系统消息
                            \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                        }
                        break;
                    case 3:
                        Db::name('users')->where('user_id',$info['user_id'])->update(['sign'=>$info['before']]);
                        $str = sprintf('您于%s修改的昵称因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                        //发送系统消息
                        \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                        break;
                    case 4:
                        Db::name('users')->where('user_id',$info['user_id'])->update(['nick_name'=>$info['before']]);
                        $str = sprintf('您于%s修改的昵称因不符合规范系统已撤回修改',date('Y-m-d H:i',$info['create_time']));
                        //发送系统消息
                        \app\api\controller\Base::sendUsrMsg('system',hashid($info['user_id']),$str);
                        break;
                }

            }

            Db::name('check')->whereOr('check_id',$data['id'])->update(['status'=>$data['status']]);
            Db::commit();
        }catch (Exception $e){
            Db::rollback();
            $this->error($e->getMessage());
        }
        $this->success('操作成功');
    }
    
    
    
    public function delete()
    {
        $this->_del('check');
    }
    



}
